cnvpmhmm = function (mhmm_out, chr = c(1:22, "X", "Y"), ...) {

dat=read.table(mhmm_out, col.names=c('start', 'end', 'states', 'len', 's_num'), header=F)
dat$states=as.character(dat$states)
stat_level = c('absent', 'deletion', 'normal', 'duplication')
stat_level_num = c(0, 1, 2, 3)
stat_col = rainbow(4)
# dat_stat = list(states=stat_level, s_num=stat_level_num)
dat_stat = data.frame(states=stat_level, s_num=stat_level_num, s_col=stat_col, stringsAsFactors=F)
dat$states = factor(dat$states, levels=stat_level)
# dat$s_num1 = NA




chr=as.character(chr)
data_path=Sys.getenv('data_path')
chr_len=paste(data_path, 'b37_chr_ln_y.RData', sep='/')
load(chr_len)
target_chr_len=b37_chr_ln[which(b37_chr_ln$chr %in% chr),]
xlim=c(1, sum(as.numeric(target_chr_len$len)))


pdf("1.cnv.mhmm.pdf", width=12, height=3)
par(pch=18, lwd = .2, ann=F, xaxs='i', yaxs='i')

plot(NA, type='n', xlim=xlim, ylim=c(-1,4), cex.axis=.5)

title(main="CNVs of single cell with mhmm", xlab="Position on the genome(bp)", ylab="Copy number states")

abline(h=c(0:3), lty=3, col='gray')

	for (i in 1:nrow(target_chr_len)) {
		pre_len = sum(as.numeric(target_chr_len$len[0:(i-1)]))
		
		chr_lab_pos=pre_len + target_chr_len$len[i] %/% 2
		
		axis(3, at=chr_lab_pos, labels=target_chr_len$chr[i],tick=F, cex.axis=.5, line=-1)
		abline(v=pre_len, lty=3, col='gray')
	}
	# for (i in nrow(dat_stat)) {

		# which(dat$states==dat_stat$states[i])
		# dat$s_num1[which(dat$states==dat_stat$states[i])] = dat_stat$s_num[i]

	# }

	for (k in 1:nrow(dat)) {
		lines(c(dat$start[k], dat$end[k]), rep(dat_stat$s_num[which(dat_stat$states==dat$states[k])], 2), col = dat_stat$s_col[(dat_stat$states==dat$states[k])], lwd=2)
	}

dev.off()
}

